package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SupSupplierInventory;
import com.ruoyi.system.service.ISupSupplierInventoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供货商存货对照Controller
 * 
 * @author ruoyi
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/system/inventory_supplier")
public class SupSupplierInventoryController extends BaseController
{
    @Autowired
    private ISupSupplierInventoryService supSupplierInventoryService;

    /**
     * 查询供货商存货对照列表
     */
    @PreAuthorize("@ss.hasPermi('system:inventory_supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupSupplierInventory supSupplierInventory)
    {
        startPage();
        List<SupSupplierInventory> list = supSupplierInventoryService.selectSupSupplierInventoryList(supSupplierInventory);
        return getDataTable(list);
    }

    /**
     * 导出供货商存货对照列表
     */
    @PreAuthorize("@ss.hasPermi('system:inventory_supplier:export')")
    @Log(title = "供货商存货对照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupSupplierInventory supSupplierInventory)
    {
        List<SupSupplierInventory> list = supSupplierInventoryService.selectSupSupplierInventoryList(supSupplierInventory);
        ExcelUtil<SupSupplierInventory> util = new ExcelUtil<SupSupplierInventory>(SupSupplierInventory.class);
        util.exportExcel(response, list, "供货商存货对照数据");
    }

    /**
     * 获取供货商存货对照详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:inventory_supplier:query')")
    @GetMapping(value = "/{relationId}")
    public AjaxResult getInfo(@PathVariable("relationId") Long relationId)
    {
        return success(supSupplierInventoryService.selectSupSupplierInventoryByRelationId(relationId));
    }

    /**
     * 新增供货商存货对照
     */
    @PreAuthorize("@ss.hasPermi('system:inventory_supplier:add')")
    @Log(title = "供货商存货对照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupSupplierInventory supSupplierInventory)
    {
        return toAjax(supSupplierInventoryService.insertSupSupplierInventory(supSupplierInventory));
    }

    /**
     * 修改供货商存货对照
     */
    @PreAuthorize("@ss.hasPermi('system:inventory_supplier:edit')")
    @Log(title = "供货商存货对照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupSupplierInventory supSupplierInventory)
    {
        return toAjax(supSupplierInventoryService.updateSupSupplierInventory(supSupplierInventory));
    }

    /**
     * 删除供货商存货对照
     */
    @PreAuthorize("@ss.hasPermi('system:inventory_supplier:remove')")
    @Log(title = "供货商存货对照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{relationIds}")
    public AjaxResult remove(@PathVariable Long[] relationIds)
    {
        return toAjax(supSupplierInventoryService.deleteSupSupplierInventoryByRelationIds(relationIds));
    }
}
